<template>
	<view class="selected-services">
		<!-- 头部 -->
		<navbar :config="config"
		@searchClick="searchClick"></navbar>
		<!-- <view class="BigPiece">
		</view> -->
		<view class="selected-services-item"> </view>
		<!-- logo -->
		<view class="shop" v-if="shop">
			<view class="item">
				<image :src="shop.logo" mode="" class="img"></image>
				<view class="item-right">
					<view class="name">{{ shop.shop_name }}</view>
					<view class="comment">
						<uni-rate :max="5" :value="shop.average" size="17" readonly="true" color="#e6e6e6"
							allowHalf='true' margin="4" activeColor="#FF721B" />
						<view class="five-stars"> {{ shop.average }}分 </view>
					</view>
				</view>
			</view>
			<view class="map" @click="openMap(shop)">
				<text class="iconfont">&#xe6db;</text>
				<view class="name"> {{ shop.map_punctuation }}{{ shop.address }} </view>
				<text class="see">[查看地图]</text>
			</view>
			<view class="map do-business" @click="callPhone">
				<text class="iconfont">&#xe632;</text>
				<view class="name">
					营业时间:{{ shop.business_hours }}{{ shop.time_quantum }}
				</view>
				<text class="see">[联系客服]</text>
			</view>
		</view>
		<!-- 限时秒杀 -->
		<view class="seckill" v-if="currSeckill && currSeckill.length > 0">
			<view class="seckill-flex">
				<view class="seckill-top" @click="goProductDetails('/pages/research/nearby/timeLimit?shopid='+shopId)">
					<view class="seckill-left"> 限时秒杀 </view>
					<view class="seckill-line" v-if="currTime"> </view>
					<view class="seckill-time" v-if="currTime">{{ currTime }}点场 剩余
					</view>
					<view class="time-item">
						<uni-countdown :backgroundColor="'none'" @timeup="overDown2" :color="'#fff'"
							:splitorColor="'#fff'" :show-day="time2[0] > 0" :day="time2[0]" :hour="time2[1]"
							:minute="time2[2]" :second="time2[3]"></uni-countdown>
					</view>
				</view>
				<view class="commodity" v-if="currSeckill && currSeckill.length > 0">
					<swiper :indicator-dots="false" :autoplay="false" :display-multiple-items="itemsDis2"
						@change="imgActiveFun2" style="height: 190rpx" circular="true">
<!-- 						<swiper-item class="option-item" @click="
                goProductDetails(
                  '/pages/product/goods/seckillGoods?id=' + item.id
                )
              " v-for="item in currSeckill" :key="item.id">
							<image v-if="item && item.cover" :src="item.cover" mode=""></image>
							<view class="number">
								<rich-text :nodes="$mUtil.priceBigSmall(item.min_price)"></rich-text>
							</view>
						</swiper-item> -->
						<swiper-item v-for="(item,key) in currSeckill" :key="key">
							<div class="fa-item">
							<view class="option-item" v-for="itemSon in item" @click="goProductDetails('/pages/product/goods/seckillGoods?id=' + itemSon.id)" :key="item.id">
							<image v-if="itemSon && itemSon.cover" :src="itemSon.cover" mode=""></image>
							<view class="number">
								<rich-text :nodes="$mUtil.priceBigSmall(itemSon.min_price)"></rich-text>
							</view>
							</view>
							</div>
						</swiper-item>
					</swiper>
					<!-- <view class="slide-box">
						<view class="dotBox" v-if="currSeckill.length > 1">
							<view class="dotBox_item" v-for="(v, i) in currSeckill" :key="i"
								:class="{ active_dotBox: activeBannerIndex2 == i }"></view>
						</view>
					</view> -->
					<view class="dotBox" v-if="currSeckill.length > 1">
						<view class="dotBox_item" v-for="(v, i) in currSeckill" :key="i"
							:class="{ active_dotBox: activeBannerIndex2 == i }"></view>
					</view>
				</view>

				<nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
			</view>
		</view>

		<!-- 拼团购 -->
		<view class="group-work" v-if="groupList && groupList.length > 0">
			<view class="group-item">
				<view class="group-top" @click="goProductDetails('/pages/research/homepage/groupList?shopid='+shopId)">
					<view class="group-left"> 拼团购 </view>
					<view class="group-right">
						查看更多<text class="iconfont u-font26 u-AAAAAA">&#xe6c7;</text>
					</view>
				</view>
				<view v-if="groupList && groupList.length > 0">
					<view class="work-item" v-for="(item, index) in groupList" :key="index" @click="
            goProductDetails('/pages/product/goods/puzzleGoods?id=' + item.id)
          ">
						<view class="work-left">
							<image :src="item.cover" class="work-image" mode=""></image>
						</view>
						<view class="work-title">
							<view class="u-text2 u-mt10" style="font-size: 32rpx;">
								{{ item.title }}
							</view>
							
							<view class="go-group-work">
								<view class="work-number">
									<view class="num">
										<view class="large">
											<rich-text :nodes="$mUtil.priceBigSmall(item.min_price)"></rich-text>
										</view>
										<view class="small">
											<text class="pintuanc6">¥ {{ item.min_sale_price }}</text>
										</view>
									</view>

									<view class="how-many-people">
										{{ item.group_people_num }}人团，已拼<text class="number">{{
                      item.result_sale_num
                    }}</text>件
									</view>
								</view>
								<view class="go-btn">去拼团</view>
							</view>
						</view>
					</view>
				</view>
				<nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
			</view>
		</view>
		<!-- 拼团购 -->
		<!-- 精品服务 -->

		<view class="boutique">
			<view class="item" :class="{ itemswitch: isActive == index }" v-for="(item, index) in service"
				:key="item.id" @click="switchAssembly(index)">
				{{ item.name }}
			</view>
		</view>

		<!-- <view class="transformation" :is="currentView"> </view> -->
		<!-- <service  v-if="isActive==0" :cate='serviceCate' :good='serviceGood' @typeChange='serviceTypeChange'></service> -->
		<commodity :cate="commCate" :good="commGood" :isActive='isActive' @typeChange="commTypeChange"></commodity>
	</view>
</template>

<script>
	import commodity from "../../../components/selected/commodity.vue";
	export default {
		components: {

			commodity,
		},
		data() {
			return {
				service: [{
						id: 1,
						name: "精品服务",
					},
					{
						id: 2,
						name: "精选商品",
					},
				],

				isActive: 0,
				config: {
					back: true, //false是tolbar页面 是则不写
					title: "店铺",
					color: "#FFFFFF",
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, "#FF721B"],
					
					search: {
						value: "",
						placeholder: "",
						disabled: true,
					},
				},
				username: 123,
				scrollTop: 0,
				old: {
					scrollTop: 0,
				},
				shop: null, //店铺信息
				currTime: null, //秒杀当前场
				currSeckill: [], //秒杀列表
				ml2: -22, //小红点偏移
				itemsDis2: 1, //当前小红点位置
				keyList2: 0, //一共几个点
				time2: [0, 0, 0, 0], //秒杀倒计时
				groupList: [],
				activeBannerIndex2: 0,

				shopId: null,
				commCate: [], //商品分类
				commGood: [], //商品列表
				commParams: {
					limit: 100000,
				},


			};
		},
		onLoad(options) {
			if (options.shopId) {
				this.shopId = options.shopId;
				this.getCommCate(options.shopId);
				this.getIndexList(options.shopId);
				this.seckillList(options.shopId);
				this.getgroupList(options.shopId);
				this.getCommGood(this.shopId);
			}
		},
		methods: {
			searchClick() {
				// console.log("dian");
				uni.navigateTo({
					url: "/pages/research/homepage/search",
				});
			},
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: this.shop.customer_service_phone
				});
			},
			switchAssembly(index) {
				this.isActive = index;
				delete this.commParams.group_id;
				delete this.commParams.type;

				this.getCommCate(this.shopId);

				this.getCommGood(this.shopId);


			},



			commTypeChange(e) {
				if (e.type == undefined) {
					delete this.commParams.type;
					this.commParams.group_id = e.groupId;
					console.log(e)
					console.log('参数')
				} else {
					delete this.commParams.group_id;
					this.commParams.type = e.type;
				}
				this.getCommGood(this.shopId);
			},


			/**商品列表 */
			getCommGood(shopId) {
				this.$http
					.get(this.isActive == 0 ? `/service/goods/list/${shopId}` : `/goods/list/${shopId}`, this.commParams,
						false)
					.then((res) => {
						if (res && res.code == 200) {
							this.commGood = res.list;
						}
					});
			},

			/**商品分类 */
			getCommCate(shopId) {

				this.$http
					.get(this.isActive == 0 ? `/servicegoods/group/all/${shopId}` : `/goods_group/all/${shopId}`, {},
						false)
					.then((res) => {
						if (res && res.code == 200) {
							this.commCate = res.list;
						}
					});


			},
			imgActiveFun2(e) {
				this.activeBannerIndex2 = e.detail.current;
			},
			goProductDetails(url) {
				uni.navigateTo({
					url: url,
				});
			},
			/**限时秒杀 */
			seckillList(shopId) {
				this.$http
					.get(
						`/marketing/seckillActivityGoods/flash-sale?shop_id=${shopId}`, {
							limit: 10,
							page: 1
						},
						false
					)
					.then((res) => {
						if (res && res.code == 200) {
							this.currTime = res.data.start_hour;
							this.currSeckill = this.oneArrToTwoArr(res.data.list)

							// if (this.currSeckill && res.data.list.length <= 4) {
							// 	this.keyList2 = 1;
							// 	this.itemsDis2 = res.data.list.length;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 4 &&
							// 	res.data.list.length <= 8
							// ) {
							// 	this.keyList2 = 2;
							// 	this.ml2 = -45;
							// 	this.itemsDis2 = 3;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 8 &&
							// 	res.data.list.length <= 12
							// ) {
							// 	this.keyList2 = 3;
							// 	this.ml2 = -68;
							// 	this.itemsDis2 = 3;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 12 &&
							// 	res.data.list.length <= 16
							// ) {
							// 	this.keyList2 = 4;
							// 	this.ml2 = -90;
							// 	this.itemsDis2 = 3;
							// }
							if (res.data.finish_time) {
								this.time2 = this.$mUtil
									.countDown(Math.floor(res.data.finish_time / 1000))
									.split(":")
									.map((val) => Number(val));
							}
						}
					});
			},
			oneArrToTwoArr(data) {
			  let newData = [];
			  let zyf = 4; //一维数组转二维数组长度(此处是二维数组每一个长度控制)
			  for (var i = 0; i < Math.ceil(data.length / zyf); i++) {
			    newData[i] = [];
			    newData[i].push(data[i * zyf]);
			    for (var j = 1; j < zyf; j++) {
			      if (data[i * zyf + j] == undefined) {
			        //超出长度控住
			        return newData;
			      } else {
			        newData[i].push(data[i * zyf + j]);
			      }
			    }
			  }
			  return newData;
			},
			/**团购 */
			getgroupList(shopId) {
				this.$http
					.get(
						`/groupbuy/activitygoods/will-you-spell?shop_id=${shopId}`, {
							limit: 10,
							page: 1
						},
						false
					)
					.then((res) => {
						if (res && res.code == 200) {
							this.groupList = res.list;
						}
					});
			},
			/**查看地图 */
			openMap(shop) {
				uni.openLocation({
					latitude: Number(shop.tx_latitude),
					longitude: Number(shop.tx_longitude),
					name:shop.name,
					address: shop.address,
					success: function() {
						console.log("success");
					},
				});
			},
			/**获取店铺基本信息 */
			getIndexList(shopid) {
				this.$http.get("/yxt/shop/info/" + shopid).then((res) => {
					uni.stopPullDownRefresh();
					this.loading = false;
					if (res.data && res.code == 200) {
						this.shop = res.data;
					}
				});
			},
			scroll: function(e) {
				// console.log(e)
				this.old.scrollTop = e.detail.scrollTop;
			},
		},
	};
</script>

<style lang="scss" scoped>
	/deep/ .hx-navbar__fixed {
		border: 1px solid rgb(255, 114, 27);
	}
	
	/deep/.hx-navbar__content__main_search_hxicon {
		span {
			font-size: 30rpx;
		}
	}
	
	/deep/.uni-input-placeholder {
		background-color: #ffffff;
		color: #474747 !important;
		font-size: 26rpx;
	}
	
	/deep/.hx-navbar__content__main_search_input {
		background-color: #ffffff;
		font-size: 30rpx;
	}
	.slider-item {
		overflow: hidden;
		width: 50rpx;
		height: 14rpx;
		opacity: 1;
		background: #ff0000;
		border-radius: 7rpx;
	}

	.slider {
		overflow: hidden;
		margin-top: 36rpx;
		width: 124rpx;
		height: 14rpx;
		opacity: 1;
		background: #ededed;
		border-radius: 7rpx;
		margin: 20rpx auto;
	}

	.BigPiece {
		height: 490rpx;
		position: relative;
		overflow: hidden;
	}

	.selected-services-item {
		position: absolute;
		top: 0rpx;
		left: -13%;
		width: 126%;
		overflow: hidden;
		height: 200px;
		border-radius: 0 0 50% 50%;
		background-color: #FF721B;
		z-index: 1;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;

		.seckill-item {
			margin-top: 13rpx;
			display: inline-block;

			.number {
				color: rgba(51, 51, 51, 1);
				text-align: center;

				.red {
					font-size: 40rpx;
				}
			}

			.seckill-img {
				width: 140rpx;
				height: 140rpx;
				margin-left: 21rpx;
				background-color: red;
			}
		}
	}

	.itemswitch {
		// border-bottom: 4px solid rgba(0, 50, 30, 1);
		color: #FF721B;
		// font-weight: 700;
	}

	.boutique {
		display: flex;
		justify-content: space-around;
		margin: 0 30rpx;
		// background-color: #fff;
		font-weight: 500;
		line-height: 30rpx;
		color: #474747;

		.item {
			padding: 50rpx 0 20rpx 0;
			margin-bottom: 26rpx;
		}
	}

	// .work-title:last-child{
	// 	border: none;
	// }

	.work-item {
		padding: 0 20rpx;
		display: flex;
		position: relative;

		.work-title {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding-top: 59rpx;
			padding-left: 25rpx;
			font-size: 32rpx;
			font-weight: Regular;
			color: #474747;
			flex: 1;

			.how-many-people {
				margin-top: 8rpx;
				height: 33rpx;
				opacity: 1;
				font-size: 24rpx;
				font-weight: 400;
				text-align: left;
				color: #474747;
				line-height: 24rpx;

				.number {
					color: #FF721B;
					font-weight: Regular;
				}
			}
		}

		.work-image {
			border-radius: 16rpx;
			width: 226rpx;
			height: 226rpx;
			background-color: red;
			margin-top: 50rpx;
			flex: 1;
		}

		.go-group-work {
			display: flex;
			align-items: flex-end;
			justify-content: space-between;

			.work-number {
				margin-top: 46rpx;
				font-weight: Bold;
				font-size: 32rpx;
				color: #FF721B;

				.num {
					display: flex;
					align-items: center;
				}

				.small {
					color: #aaaaaa;
					font-size: 22rpx;
					font-weight: 500;
					text-decoration: line-through;
					margin-left: 17rpx;
				}

				.work-red {
					font-size: 36rpx;
					font-weight: Bold;
					margin-left: 5rpx;
				}
			}

			.go-btn {
				background-color: #FF721B;
				color: #ffffff;
				padding: 11rpx 27rpx 11rpx 27rpx;
				border-radius: 32rpx;
				font-size: 28rpx;
				font-weight: 500;
			}
		}
	}

	.group-work {
		margin: 0 30rpx;

		.group-item {
			margin-bottom: 20rpx;
			background-color: #ffffff;
			margin-top: 50rpx;
			border-radius: 20rpx;
			padding-bottom: 30rpx;

			.group-top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 30rpx 0 30rpx;
				padding: 30rpx 0;
				border-bottom: 1rpx solid rgba(230, 230, 230, 1);

				.group-left {
					color: #474747;
					font-size: 36rpx;
					font-weight: Bold;
				}

				.group-right {
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(51, 51, 51, 1);

					.iconfont {
						// font-size: 10rpx;
						color: #666666;
						margin-left: 10rpx;
					}
				}
			}
		}
	}

	.commodity {
		//   display: flex;
		position: relative;
		//   padding: 12rpx 20rpx;
		margin: 20rpx 0;

		/deep/ .uni-swiper-slide-frame {
			width: 26% !important;
		}
		.fa-item {
			display: flex;
		}
		.option-item:first-child {
			margin-left: 0;
		}
		.option-item {
			margin-left: 24rpx;
		
			image {
				width: 140rpx;
				height: 140rpx;
			}
		
			.number {
				margin-top: 4rpx;
				text-align: center;
				font-size: 24rpx;
				// font-weight: Bold;
				line-height: 24rpx;
				color: #474747;
				// width: 140rpx;
				text {
					font-size: 28rpx;
					font-weight: Medium;
				}
			}
		}
	}

	.dotBox {
		position: absolute;
		bottom: 0rpx;
		left: 50%;
		transform: translateX(-50%);
		height: 14rpx;
		overflow: hidden;
		border-radius: 14rpx;
		background-color: #ccc;
		display: flex;
		justify-content: center;

		.dotBox_item {
			width: 45rpx;
			height: 14rpx;
			border-radius: 2rpx;
			background-color: #ccc;
			transition: all 0.5s;
		}

		.active_dotBox {
			width: 45rpx;
			background: rgba(254, 70, 3, 1);
			transition: all 0.5s;
		}
	}

	.seckill {
		color: #fefefe;
		margin-top: 45rpx;
		margin: 45rpx 30rpx;

		.seckill-flex {
			overflow: hidden;
			// margin: auto;
			background-color: rgba(255, 255, 255, 1);
			border-radius: 20rpx;
			padding: 0 29rpx;
			.seckill-top {
				display: flex;
				align-items: center;
				margin: 0;
				padding: 30rpx 0;
				border-bottom: 1rpx solid #e6e6e6;

				.seckill-left {
					color: black;
					font-size: 36rpx;
					font-weight: 700;
					font-weight: Bold;
					padding-right: 16rpx;
				}

				.seckill-line {
					margin: 0 16rpx;
					width: 1rpx;
					height: 33rpx;
					background-color: #707070;
				}

				.seckill-time {
					font-size: 24rpx;
					font-weight: 400;
					color: #666;
				}

				.time-item {
					background: #FF721B;
					padding: 0 15rpx;
					font-size: 24rpx;
					margin-left: 30rpx;
					border-radius: 17rpx;
				}
			}
		}
	}

	.shop {
		position: relative;
		box-shadow: 1rpx 1rpx 1rpx #f7f7f7;
		margin: -105rpx 30rpx 0 30rpx;
		background-color: white;
		border-radius: 25rpx;
		z-index: 10;

		.map {
			display: flex;
			padding: 0 20rpx;
			margin-top: 24rpx;
			font-weight: 400;
			font-size: 24rpx;
			font-weight: 400;

			.iconfont {
				color: #163c2a;
				margin-right: 12rpx;
			}

			.name {
				font-size: 24rpx;
				color: #474747;
				font-weight: 400;
				width: 440rpx;
			}

			.see {
				color: #fe9000;
				margin-left: 20rpx;
			}
		}

		.do-business {
			display: flex;
			align-items: center;
			font-style: 24rpx;
			font-weight: 400;
			color: #333333;
			margin-top: 26rpx;
			padding: 0 20rpx 34rpx 20rpx;

			.iconfont {
				color: #163c2a;
				margin-right: 12rpx;
			}
		}

		.item {
			display: flex;

			.img {
				width: 200rpx;
				height: 200rpx;
				background-color: #fff;
				margin-top: -75rpx;
				border-radius: 20rpx;
				margin-left: 15rpx;
				/* display: none; */
			}

			.item-right {
				margin-top: 30rpx;

				.name {
					font-size: 32rpx;
					color: #474747;
					font-weight: Bold;
					margin-left: 21rpx;
					font-size: 32rpx;
				}

				.comment {
					margin-top: 10rpx;
					padding-left: 16rpx;
					align-items: center;
					display: flex;

					.iconfont {
						color: #ff4e15;
						padding-left: 10rpx;
					}

					.five-stars {
						margin-left: 16rpx;
						font-size: 28rpx;
						font-weight: Medium;
						color: #FF721B;
					}
				}
			}
		}
	}

	.selected-services {
		background-color: #fafafa;
		// background: url(https://zhongyi-shop.oss-cn-beijing.aliyuncs.com/songhe/weixin/static/background.png);
		padding-top: 200rpx;
		position: relative;

		overflow-x: hidden;
	}
</style>
